stage.set_background("underwater")
sprite = codesters.Sprite("fish")
sprite.go_to(-100, -220)
stage.disable_floor()
stage.set_gravity(4)
sprite.set_gravity_off()
t = codesters.Teacher()
func = t.find_block('def')
call = t.find_function('event_key')
try:
lefts = t.find_function("move_left")
tval3 = lefts[0][1]
tval4 = t.get_indent_at_line(lefts[0][0])
except:
lefts = "DNE"
tval3 = "DNE"
tval4 = "DNE"
try:
rights = t.find_function('move_right')
tval5 = rights[0][1]
tval6 = t.get_indent_at_line(rights[0][0])
except:
rights = "DNE"
tval5 = "DNE"
tval6 = "DNE"
try:
tval7 = t.get_indent_at_line(func[0][0])
except:
tval7 = -1
try:
tval8 = t.get_indent_at_line(func[1][0])
except:
tval8 = -1
try:
right_event = t.find_text('right_key')
left_event = t.find_text('left_key')
except:
right_event = "DNE"
left_event = "DNE"
t1 = TestObjective()
t1.add_success(len(func) == 2, "Great job!")
t1.add_failure(len(func) == 0, "Did you add the key events?")
t1.add_failure(len(func) < 2 and len(func) > 0, "Did you add a left and right key event?")
# t2 = TestObjective()
# t2.add_success(tval7 == 0 and tval8 == 0, "Great job!")
# t2.add_failure(tval7 > 0 or tval8 > 0, "The def line of a key event should NOT be indented!\nTry deleting the events and re-adding them.")
t3 = TestObjective()
t3.add_success(tval4 == 4, "Great job!")
t3.add_failure(tval3 == "DNE", "Oops! Did you delete the .move_left() command in your event?")
t3.add_failure(tval4 < 4, "Make sure your .move_left() command is indented 4 spaces in your left key event.")
t3.add_failure(tval4 > 4, "Make sure your .move_left() command is indented only 4 spaces inside your left key event.")
t4 = TestObjective()
t4.add_success(tval6 == 4, "Great job!")
t4.add_failure(tval5 == "DNE", "Oops! Did you delete the .move_right() command in your event?")
t4.add_failure(tval6 < 4, "Make sure your .move_right() command is indented 4 spaces in your right key event.")
t4.add_failure(tval6 > 4, "Make sure your .move_right() command is indented only 4 spaces inside your right key event.")
t5 = TestObjective()
t5.add_failure(len(right_event) != 2, "Oops! Do you have a right_key event handler?")
t5.add_failure(len(left_event) != 2, "Oops! Do you have a left_key event handler?")
tester = TestManager()
tester.add_test_list([t1, t3, t4, t5])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)